// pages/xiangqing/xiangqing.js
const db = wx.cloud.database()
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
   title:"",
   poster:"",
   bofang:"",
   gaishu:"",
   jianjie:"",
   time:"",
   type:"",
   translation:"",
   people:"",
   peopleimage:"",
   peoplestatus:"",
   peoplelist:[],
   current: 0,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
  },
  onShow() {
    // 获取当前小程序的页面栈     
    let pages = getCurrentPages()
    // 数组中索引最大的页面--当前页面  
    let currentPage = pages[pages.length-1]
    var options = currentPage.options

    if (typeof(options.id) !== 'undefined') {
      var that = this
      db.collection('movies').where({
        _id: options.id
      }).get().then(res => {
        wx.setNavigationBarTitle({
          title: res.data[0].title
        });
        that.setData({
          title: res.data[0].title,
          id: res.data[0]._id,
          poster:res.data[0].poster,
          bofang:res.data[0].bofang,
          duration:res.data[0].duration,
          gaishu:res.data[0].gaishu,
          jianjie:res.data[0].jianjie,
          time:res.data[0].time,
          year:res.data[0].year,
          type:res.data[0].type,
          translation:res.data[0].translation,
          people:res.data[0].people,
          peopleimage:res.data[0].peopleimage,
          peoplestatus:res.data[0].peoplestatus,
        });
        let peoplelist=[]
        let arr1=res.data[0].people
        let arr2=res.data[0].peopleimage
        let arr3=res.data[0].peoplestatus
        for(let i=0; i<arr1.length;i++)
          peoplelist.push({people:arr1[i],
            peopleimage:arr2[i],
            peoplestatus:arr3[i]})
         this.setData({
          peoplelist: peoplelist
        })
        console.log(peoplelist)
        });        
    }
  },
  onMovieTap: function (event) {
    const id = event.currentTarget.dataset.id;
    console.log(id)
    wx.navigateTo({
      url: `/pages/cinema/cinema?id=${id}`
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
})